import { Global } from "../../../../../com/gengine/global/Global";
import { DragItemEvent } from "./DragItemEvent";
import { CursorManager } from "../../../manager/CursorManager";
//class DragItem
    
    export  class DragItem /* flash.display.Sprite */
    {
        constructor(arg1: number=250, arg2: number=5)
        {
            
            this.__width = arg1;
            this.__height = arg2;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.graphics.beginFill(16777215, 0.01);
            this.graphics.drawRect(0, 0, this.__width, this.__height);
            this.graphics.endFill();
            this.addListeners();
            return;
        }

        /* internal  */addListeners(): void
        {
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseHandler);
            this.addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrameHandler);
            return;
        }

        /* internal  */onMouseHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.type;
            switch (loc1) 
            {
                case flash.events.MouseEvent.MOUSE_OVER:
                {
                    this._isOver = true;
                    this._isChange = true;
                    break;
                }
                case flash.events.MouseEvent.MOUSE_DOWN:
                {
                    this._isDown = true;
                    this._isChange = true;
                    this._lastDragX = Global.stage.mouseX;
                    this._lastDragY = Global.stage.mouseY;
                    this.dispatchEvent(new DragItemEvent(DragItemEvent.StartDrag));
                    Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseHandler);
                    break;
                }
                case flash.events.MouseEvent.MOUSE_OUT:
                {
                    this._isOver = false;
                    this._isChange = true;
                    break;
                }
                case flash.events.MouseEvent.MOUSE_UP:
                {
                    this._isDown = false;
                    this._isChange = true;
                    Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseHandler);
                    break;
                }
            }
            return;
        }

        /* internal  */onEnterFrameHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=NaN;
            var loc2=NaN;
            if (this._isChange) 
            {
                if (this._isOver || this._isDown) 
                {
                    CursorManager.showCursor(CursorManager.Zoom);
                }
                else if (!CursorManager.isSkill()) 
                {
                    CursorManager.hideCursor();
                }
                this._isChange = false;
            }
            if (this._isDown) 
            {
                loc1 = Global.stage.mouseX - this._lastDragX;
                loc2 = Global.stage.mouseY - this._lastDragY;
                this.dispatchEvent(new DragItemEvent(DragItemEvent.DragPositionChange, loc1, loc2));
            }
            return;
        }

        /* internal */ /* var */__width: number;

        /* internal */ /* var */__height: number;

        /* internal */ /* var */_isDown: Boolean;

        /* internal */ /* var */_isOver: Boolean;

        /* internal */ /* var */_isChange: Boolean;

        /* internal */ /* var */_lastDragX: number;

        /* internal */ /* var */_lastDragY: number;
    }
